# Django AdminLTE3 Simple Start Script
# Simple version to avoid encoding issues

Write-Host "Starting Django AdminLTE3 project..." -ForegroundColor Green

# Check if virtual environment exists
if (-not (Test-Path ".venv")) {
    Write-Host "Error: Virtual environment does not exist, please run setup_simple.ps1 first" -ForegroundColor Red
    exit 1
}

# Activate virtual environment
Write-Host "Activating virtual environment..." -ForegroundColor Yellow
& ".venv\Scripts\Activate.ps1"

# Check if Django project exists
if (-not (Test-Path "manage.py")) {
    Write-Host "Error: Django project does not exist, please run setup_simple.ps1 first" -ForegroundColor Red
    exit 1
}

# Check if database needs migration
Write-Host "Checking database..." -ForegroundColor Yellow
python manage.py migrate --check 2>$null
if ($LASTEXITCODE -ne 0) {
    Write-Host "Initializing database..." -ForegroundColor Yellow
    python manage.py migrate
}

# Start development server
Write-Host "Starting development server..." -ForegroundColor Yellow
Write-Host "Project will be available at http://127.0.0.1:8000" -ForegroundColor Green
Write-Host "Press Ctrl+C to stop the server" -ForegroundColor Yellow

python manage.py runserver
